﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>盘点任务</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script type="text/html" id="barDemo">
        <a title="盘点清单" href="javascript:;" lay-event="dList"><i class="layui-icon">&#xe615;</i></a>
        <a title="已盘清单" href="javascript:;" lay-event="sp"><i class="layui-icon">&#xe601;</i></a>
        {{# if(d.status !='pct-stop' && d.status !='pct-report'){}}
        <a title="终止" href="javascript:;" lay-event="stop" id="update"><i class="layui-icon">&#xe651;</i></a>
        {{# }}}
        {{# if(d.status !='pct-report'){}}
        <a title="删除" href="javascript:;" lay-event="del" id="del"><i class="layui-icon">&#xe640;</i></a>
        {{# }}}

    </script>

</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="venCode" placeholder="盘点单号" autocomplete="off" class="layui-input" id="venCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="wareName" placeholder="仓库名称" autocomplete="off" class="layui-input" id="wareName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="positionName" placeholder="货位名称" autocomplete="off" class="layui-input" id="positionName">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="proCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="proCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                            </div>

                            @*<div class="layui-inline layui-show-xs-block">

            <select id="status" name="status">
                <option value="">盘点状态</option>
            </select>
        </div>*@
                            <div class="layui-inline layui-show-xs-block">
                                <input type="hidden" name="cStatus" id="cStatus">
                                <select multiple="multiple" lay-filter="multiple" id="status" name="status"></select>
                            </div>

                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-filter="sreach" id="userSearch-view" type="button" onclick="loadData()"><i class="layui-icon">&#xe615;</i></button>
                            </div>

                        </form>
                    </div>
                    <div class="layui-card-header">
                        <button class="layui-btn" id="bar-update" type="button" onclick="createTask()"><i class="layui-icon"></i>创建任务</button>
                        <button class="layui-btn" id="btnReport-createReport" type="button" onclick="cReport()"><i class="layui-icon">&#xe63c;</i>生成报告</button>
                        <span style="margin-left: 20px; padding: 7px; background-color: #C3FDB8; font-size: Xx-small">已生成报告</span>
                    </div>
                    <div class="layui-card-body layui-table-body" id="layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

<script>
    var currPage = 1;//首先默认值为1，防止出错
    var pchCodes = "";
    function loadData() {
        GetSelectMore();
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
                { type: 'checkbox', fixed: 'left' }
              , { field: 'id', title: 'ID', width: 80 }
                , { field: 'venCode', align: 'center',title: '盘点单号', width: '8%' }
                , { field: 'wareName', align: 'center', title: '仓库名称', width: '8%' }
                , { field: 'positionName', align: 'center', title: '货位', width: '8%' }
                , { field: 'proCode', align: 'center', title: '存货编码', width: '10%' }
                , { field: 'proName', align: 'center', title: '存货名称', width: '13%' }
                , { field: 'chTypeName', align: 'center', title: '盘点类型', width: '8%' }
                , { field: 'createtime', align: 'center', title: '创建时间', width: '10%' }
                , { field: 'statusName', align: 'center', title: '任务状态', width: '8%' }
                , { field: 'right', align: 'center',title: '数据操作', toolbar: '#barDemo', width: '6%', fixed: 'right' }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
                currPage = curr;
                TablePowerHide();
                $.each(res['data'], function (i, j) {
                    if (j['status'] == "pct-report") {
                        TableRowColor('layui-table-main', i, '#C3FDB8');//已生成报告
                    }
                });
            }
            , url: "../ProCheck/GetDataList?dataType=task&condition=" + conditon
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [15, 30, 50]
            , limit: 15 //每页默认显示的数量
            , id: "tData"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'del') {
                    layer.confirm('确认要删除选中任务？', function (index) {
                        var info = DelData(data.pchCode);

                        if (info.Result) {
                            obj.del();
                        } else {
                            layer.msg(info.Message);
                        }
                        layer.close(index);
                    });
                } else if (obj.event == 'dList') {
                    var title = "盘点单号：" + data.erpCode + "（" + data.chTypeName + "）明细";
                    OpenPage(title, '../ProCheck/CheckTaskList?dataType=chyp&pchCode=' + data.pchCode);
                }
                else if (obj.event == 'stop') {
                    layer.confirm('确认要中止此任务？', function (index) {
                        $.ajax({
                            url: "../ProCheck/StopCheckTask",
                            data: { pchCode: data.pchCode },
                            dataType: "json",
                            type: "POST",
                            async: false,
                            success: function (data) {
                                loadData();
                            }
                        });
                        layer.close(index);
                    });
                } else if (obj.event == 'sp') {
                    OpenPage(data.erpCode + "（" + data.chTypeName + "）-实盘清单", '../ProCheck/TaskRecords?pchCode=' + data.pchCode);
                }

            });
            //监听工具条
            table.on('checkbox(list)', function (obj) {
                var data = obj.data;
                var checkStatus = table.checkStatus('tData');
                pchCodes = "";
                for (var i = 0; i < checkStatus.data.length; i++) {
                    if (checkStatus.data[i].status != "pct-doing") {
                        layer.msg("此任务不能生成报告：" + checkStatus.data[i].erpCode); return;
                    }
                    pchCodes += checkStatus.data[i].pchCode + ",";
                }
                pchCodes = pchCodes.substr(0, pchCodes.length - 1);

            });
        });
    }

    layui.config({
        base: '../Content/Scripts/formSelect/',
    })
    layui.use(['multiSelect'], function () {
        var $ = layui.jquery, form = layui.form, multiSelect = layui.multiSelect;
    });
    function GetSelectMore() {
        var vals = [],
            texts = [];
        $('select[multiple] option:selected').each(function () {
            vals.push($(this).val());
            texts.push($(this).text());
        })
        $("input[ name='cStatus']").val(vals.join(','));

    }

    $(function () {
        DictionaryDropDown("pcst", "status", "");
        WebPowersShow();
        loadData();
   
    })

    function createTask() {
        InfoOpenPage("../ProCheck/UpdateTask?dataId=0", "创建盘点任务", "80%", "90%");
    }

    /**
删除任务
**/
    function DelData(pchCode) {
        var info = undefined;
        $.ajax({
            url: "../ProCheck/DelCheckTask",
            data: { pchCode: pchCode },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                info= data;
            }
        });
        return info;
    }
    /**
    生成盘点报告
    **/
    function cReport() {
        if (pchCodes != "") {
                var loadwin = layer.load(2, {
                    shade: [0.3, '#424242'],
                    content: '生成中',
                    success: function (layerContentStyle) {
                        layerContentStyle.find('.layui-layer-content').css({
                            'padding-top': '35px',
                            'text-align': 'left',
                            'width': '120px'
                        });
                    }
                }, { shadeClose: true });
                $.ajax({
                    url: '../ProCheck/createReport',
                    data: { pchCodes: pchCodes },
                    dataType: "json",
                    type: "POST",
                    success: function (data) {
                        if (data.Result) {
                            layer.msg("报告生成成功");
                            var conditon = JSON.stringify(FormToJson("qForm"));
                            reLoadTable("tData", "../ProCheck/GetDataList?dataType=task&condition=" + conditon,currPage);
                        } else {
                            layer.msg(data.Message);
                        }
                        layer.close(loadwin);
                    }
                });
            } else {
            layer.msg("请先选择盘点任务"); return;
            }
    }

</script>